<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.util.*" %>
    
<%@page import="javax.servlet.jsp.tagext.TryCatchFinally"%>
<%@page import="web1.bean.user"%>



    
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
 <base href="<%=basePath%>">   
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>标题</title>        
  <meta http-equiv="pragma" content="no-cache">
  <meta http-equiv="cache-control" content="no-cache">
  <meta http-equiv="expires" content="0">    
  <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  <meta http-equiv="description" content="This is my page">
</head>

  <body>
   <h1>测试JSTL标签库</h1>
   <ul>
       <li>采用 c:out 标签</li>
       hello(使用标签)：<c:out value="123"></c:out> <br>
       hello(使用标签，结合EL表达式)：<c:out value="${hello }"></c:out><br>
       hello(使用EL表达式)：${hello }<br>
       hello(使用EL表达式,default)：${hello123 }<br>
       hello(使用标签，结合EL表达式,缺省值)：<c:out value="${hello123 }" default="hello123"></c:out><br>
       hello(使用标签，结合EL表达式,缺省值)：<c:out value="${hello123 }" >hello123</c:out><br>
      welcome(使用EL表达式)：${welcome } <br>
      welcome(使用标签,escapeXml=true,EL表达式):<c:out value="${welcome }" escapeXml="true"></c:out> <br>
      welcome(使用标签,escapeXml=false,EL表达式):<c:out value="${welcome }" escapeXml="false"></c:out> <br>
      *********************************************
      <li>测试c:set 和 c:remove</li>
      <c:set value="juyahong" var="userId"></c:set><br>
      userId:--->${userId } <br>
      <c:remove var="userId"/> <br>
      userId:--->${userId } <br>
      *********************************************
      <li>条件控制标签：--->c:if</li>
      <c:if test="${v1 lt v2 }">
          v1 小于v2 <br>
      </c:if>
      
      *********************************************
      <li>条件控制标签：c:choose,c:when,c:otherwise</li>
      <c:choose>
          <c:when test="${v1 gt v2 }">
              v1大于v2<br>
          </c:when>
          <c:otherwise>
              v1小于v2<br>
          </c:otherwise>
      </c:choose>
      
      <c:choose>
          
          <c:when test="${empty userList }">
          没有符合条件的数据<br>
          </c:when>
          <c:otherwise>
              存在用户数据<br>
          </c:otherwise>
      </c:choose>
      *********************************************
      <li>循环控制标签：--->c:forEach</li>
      <h3>采用jsp脚本显示</h3>
 
      <table border="1px">
          <tr>
              <td>用户姓名</td>
              <td>用户年龄</td>
              <td>所属组</td>
          </tr>
          <%
              List userList=(List)request.getAttribute("users");
              if(userList == null || userList.size()==0){
          %>
              <tr>
                  <td colspan="3">没有符合条件的数据</td>
              </tr>
          <% 
              }else {
              for(Iterator iter=userList.iterator();iter.hasNext();){
                   user user=(user)iter.next();
           %>
                   <tr>
                       <td><%=user.getName() %></td>
                       <td><%=user.getAge() %></td>
                       <td><%=user.getGroup().getName() %></td>
                   </tr>
           
           <%
                   }
                 }
            %>
      </table>
      <h3>采用c:forEach 标签</h3>
      <table border="1px">
          <tr>
              <td>用户姓名</td>
              <td>用户年龄</td>
              <td>所属组</td>
          </tr>
          <c:choose>
              <c:when test="${empty users }">
              <tr>
                  <td colspan="3">没有符合条件的数据</td>
              </tr>
              </c:when>
              <c:otherwise>
                  <c:forEach items="${users }" var="user">
                      <tr>
                          <td>${user.name }</td>
                          <td>${user.age }</td>
                          <td>${user.group.name }</td>
                      </tr>
                  </c:forEach>
              </c:otherwise>
          </c:choose>
      </table>
      <h3>采用c:forEach ,varstatus</h3>
      <table border="1px">
          <tr>
              <td>用户姓名</td>
              <td>用户年龄</td>
              <td>所属组</td>
          </tr>
          <c:choose>
              <c:when test="${empty users }">
                  <tr>
                      <td colspan="3">没有符合条件的数据</td>
                  </tr>
              </c:when>
              <c:otherwise>
                  <c:forEach items="${users }" var="user" varStatus="vs">
                      <c:choose>
                          <c:when test="${vs.count mod 2==0 }">
                              <tr bgcolor="red">
                          </c:when>
                          <c:otherwise>
                              <tr>
                          </c:otherwise>
                      </c:choose>
                                  <td>${user.name }</td>
                                  <td>${user.age }</td>
                                  <td>${user.group.name }</td>
                              </tr>
                  </c:forEach>
              
              </c:otherwise>
          </c:choose>
      </table>
      <li>循环控制标签forEach：输出map</li>
      <c:forEach items="${map }" var="entry">
          ${entry.key } ,${entry.value } <br>
      </c:forEach>
      <li>循环控制标签forTokens</li>
      <c:forTokens items="${strTokens} " delims="#" var="v">
          ${v } <br>
      </c:forTokens>
      <li>c:catch标签</li>
  <p>
      <%
          try{
              Integer.parseInt("ahkjdhfjk");
          } catch(Exception e){
              out.println(e.getMessage());
          }
       %>
  </p>
  <P>
      <c:catch var="msg">
          <%
          Integer.parseInt("ahkjdhfjk");
           %>
      </c:catch>
      ${msg }
  </P>
      
   </ul>
  </body>
</html>
